package com.net.xpay.common.validator;



import com.google.common.base.Strings;
import com.net.xpay.core.constant.PoseidonErrorCode;
import com.net.xpay.core.model.UserBusinessAuthModel;
import com.net.common.exception.BusinessException;
import com.net.common.util.PhoneUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 企业实名认证参数验证
 */
@Slf4j
@Component
public class UserBusinessAuthValidator {

    public void validateUserBusinessAuth(UserBusinessAuthModel model){
        if (Strings.isNullOrEmpty(model.getBusinessLicense())){
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL,"法人营业执照不可为空");
        }
        if (Strings.isNullOrEmpty(model.getBusinessName())){
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL,"企业名称不可为空");
        }
        if (model.getBusinessName().length() > 64){
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL,"企业名称不能超过64个字");
        }
        if (Strings.isNullOrEmpty(model.getUniformSocialCreditCode())){
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL,"统一社会信用代码不可为空");
        }
        if (Strings.isNullOrEmpty(model.getIdCardFront())){
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL,"法人身份证正面照不可为空");
        }
        if (Strings.isNullOrEmpty(model.getIdCardBack())){
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL,"法人身份证反面照不可为空");
        }
        if (Strings.isNullOrEmpty(model.getName())){
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL,"法人姓名不可为空");
        }
        if (Strings.isNullOrEmpty(model.getIdCard())){
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL,"法人身份证号不可为空");
        }
        if (Strings.isNullOrEmpty(model.getPhone())){
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL,"法人手机号不可为空");
        }
        if (!PhoneUtil.isEffectiveMobile(model.getPhone())) {
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "手机号格式不正确");
        }


    }
}
